var initialState={
    count:1,
    num:0,
    price:0,    
    list:{
        rows:[],
        total:0
    },
}


function reducer(state=initialState,action){
    switch(action.type){
        case 'INCREASE': 
            //return {count: state.count + 1}//直接修改state--会有问题--是错的
            //1.克隆--使用纯函数来实现
            //return Object.assign({},state,{count: state.count + 1})
            //2.
            return {...state,count: state.count + 1}
        case 'DECREASE': 
            //return {count1: state.count1 - 1}
            //return Object.assign({},state,{count1: state.count1 - 1})
            return {...state,count: state.count - 1}
        case 'TOONE': 
            //console.log(action.payload);
            return {...state,count: 1}
        case 'GETLISTDATA': 
            //console.log(action.payload);
            return {...state,list: action.payload}
        case 'RAGE': 
            //console.log(action.payload);
            return {...state,count: state.count<=1?1:state.count}
        default: 
            return state;
    }
}

export default reducer;